package com.quectel.sdk.kuangshi.monitor;

import com.fasterxml.jackson.core.type.TypeReference;
import com.quectel.util.http.HttpRestUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;

import javax.net.ssl.SSLContext;

/**
 * 在这里编写说明
 *
 * @author: rananxin
 * @email: ryan.ran@quectel.com
 * @date: 2023-01-03 16:10:00
 */
public class BoxTest {

    private static final HttpRestUtils HTTP_REST_UTILS;

    static {
        SSLContext sslContext = null;
        try {
            sslContext = SSLContexts.custom().loadTrustMaterial(null, (TrustStrategy) (x509Certificates, s) -> true).build();
        } catch (Exception e) {
            e.printStackTrace();
        }

        RequestConfig defaultRequestConfig = RequestConfig.custom()
                .setSocketTimeout(5000)
                .setConnectTimeout(5000)
                .setConnectionRequestTimeout(5000)
                .build();

        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "dh123456"));
        HttpClient sslHttpClient = HttpClients.custom()
                .setDefaultRequestConfig(defaultRequestConfig)
                .setSslcontext(sslContext)
                .setSSLHostnameVerifier(new NoopHostnameVerifier())
                .setMaxConnTotal(500)
                .setMaxConnPerRoute(100)
                //重试1次
                .setRetryHandler(new DefaultHttpRequestRetryHandler(5, false))
                .setDefaultCredentialsProvider(credsProvider)
                .build();
        HTTP_REST_UTILS = HttpRestUtils.getInstance(sslHttpClient);
    }

    public static void main(String[] args) {
//        Pair<Integer, String> integerStringPair = HTTP_REST_UTILS.get("https://10.88.107.15/v1/MEGBOX/configs", null, null, new TypeReference<String>() {
//        });
//        System.out.println(integerStringPair.getRight());

//        Pair<Integer, String> integerStringPair = HTTP_REST_UTILS.get("https://10.88.107.15/v1/MEGBOX/devices", null, null, new TypeReference<String>() {
//        });
//        System.out.println(integerStringPair.getRight());

        Pair<Integer, String> integerStringPair = HTTP_REST_UTILS.get("https://10.88.107.15/v1/MEGBOX/multiAlgVideos", null, null, new TypeReference<String>() {
        });
        System.out.println(integerStringPair.getRight());
    }
}
